<!DOCTYPE html>
<html>
<head>
    <title>模块分类管理</title>
    <include file='public/head'>
        <style>
            table th, table td{text-align: center;}
        </style>
</head>
<body>
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <php> $currentTab = 6 ;</php>
	        <include file="public/nav" />
        </ul>
        <div class="rows margin-top-20">
        	<div class="col-md-6">
        		<table class="table table-bordered">
		        	<thead>
		        		<tr>
		        			<th>序号</th>
			        		<th>分类名称</th>
			        		<th>操作<?php if( cmf_auth_check(cmf_get_current_admin_id(),'plugin/appmarket/moduleCategory/add')){ ?> <a href="javascript:;" class="btn btn-info  btn-sm" onclick="addCategory();">添加分类</a><?php } ?></th>
		        		</tr>
		        	</thead>
		        	<tbody>
		        		<volist name="categoryList" id="vo"> 
			        		<tr>
			        			<td>{++$key}</td>
			        			<td>{$vo.name}</td>
			        			<td>
									<if condition="cmf_auth_check(cmf_get_current_admin_id(),'plugin/appmarket/moduleCategory/edit')">
										<a href="javascript:;" onclick="editCategory({$vo.id});" class="btn btn-info btn-sm">编辑</a>
									</if>
									<if condition="cmf_auth_check(cmf_get_current_admin_id(),'plugin/appmarket/moduleCategory/delete')">
										<a href="{:cmf_plugin_url('Appmarket://ModuleCategory/delete')}?id={$vo.id}" data-msg="确定要删除分类？" class="btn btn-danger btn-sm zy-ajax-confirm">删除</a>
									</if>
			        			</td>
			        		</tr>
		        		</volist>
		        	</tbody>
		        </table>
        	</div>
        </div>
        
    </div>
<include file='public/scripts'>
<script src="__STATIC__/js/layer/layer.js"></script>
<script src="__STATIC__/js/custom/custom.js"></script>
<script>
//添加分类
var addCategory = function(){
	let url = '{:cmf_plugin_url("Appmarket://ModuleCategory/add")}';
	layer.open({
		type: 2,
		area: ['400px', '200px'],
		fixed: false, //不固定
		maxmin: false,
		content: url,
		btn:['保存','取消'],
		title:'添加分类',
		yes:function( index ){
			var res = window["layui-layer-iframe" + index].getData();
			console.log(res);
			if( false == res ){
				layer.msg('分类名称不能为空！');
				return false;
			}
			$.post( '{:cmf_plugin_url("Appmarket://ModuleCategory/operateCategory")}' , res , function(data){
				let icon  = ( data.code == 200 ) ? 1 : 5 ; 
				layer.msg( data.message , { icon : icon });
				if( icon == 1 ){
					setTimeout( function(){
						window.location.reload();
					},1200);
				}	
			} , 'json');
		}
	});
}

//编辑分类
var editCategory = function( id )
{
	let url = '{:cmf_plugin_url("Appmarket://ModuleCategory/edit")}?id='+id;
	layer.open({
		type: 2,
		area: ['400px', '200px'],
		fixed: false, //不固定
		maxmin: false,
		content: url,
		btn:['保存','取消'],
		title:'修改分类',
		yes:function( index ){
			var res = window["layui-layer-iframe" + index].getData();
			if( res.id == 0 ){
				layer.msg('数据获取错误！');
				return false;
			}
			if( false == res ){
				layer.msg('分类名称不能为空！');
				return false;
			}
			$.post( '{:cmf_plugin_url("Appmarket://ModuleCategory/operateCategory")}' , res , function(data){
				let icon  = ( data.code == 200 ) ? 1 : 5 ; 
				layer.msg( data.message , { icon : icon });
				if( icon == 1 ){
					setTimeout( function(){
						window.location.reload();
					},1200);
				}	
			} , 'json');
		}
	});
}
</script>
</body>
</html>